home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.1 (User) / OpenStep 4.1 (User).iso / NextAdmin / NetInstallHelper.app / setup_netinstall_client < prev    next >
Encoding:
Text File  |  1995-02-17  |  7.4 KB  |  298 lines

  1. #!/bin/csh -f
  2. #
  3. # Set up a NetInstall client
  4. # Copyright (C) 1994 by NeXT Computer, Inc.  All rights reserved.
  5.  
  6. # Configuration variables.  
  7.  
  8. set CONFIG_DOMAIN=/
  9. set PARENT_DOMAIN=-UNKNOWN-
  10. set CLIENT_NAME=-UNKNOWN-
  11. set SERVER_NAME=-UNKNOWN-
  12.  
  13. # Trap SIGINT. This keeps the tty from getting messed up if
  14. # someone types ^C while the shell is reading a password.
  15.  
  16. onintr -
  17.  
  18. # All command names are stored in variable 
  19.  
  20. set AWK=/bin/awk
  21. set BASENAME=/usr/bin/basename
  22. set CAT=/bin/cat
  23. set ECHO=/bin/echo
  24. set ERROR=$ECHO
  25. set GREP=/bin/grep
  26. set HEAD=/usr/ucb/head
  27. set LS=/bin/ls
  28. set NIUTIL=/usr/bin/niutil
  29. set RM=/bin/rm
  30. set SLEEP=/usr/bin/sleep
  31. set STTY=/bin/stty
  32. set WC=/usr/ucb/wc
  33. set ARCH_CMD=/usr/bin/arch
  34.  
  35. set TRUE=1
  36. set FALSE=0
  37.  
  38. # Determine host architecture
  39.  
  40. #set ARCH=-UNKNOWN-
  41. set ARCH=`$ARCH_CMD`
  42.  
  43. #$CAT /usr/lib/NextStep/software_version | $GREP Lightning > /dev/null
  44. #if ($status == 0) then
  45. if ($ARCH == m68k) then
  46.         set ARCH=NeXT
  47. else
  48. #$CAT /usr/lib/NextStep/software_version | $GREP Thunder > /dev/null
  49. #if ($status == 0) then
  50. if ($ARCH == i386) then
  51.         set ARCH=i386
  52. else
  53. #$CAT /usr/lib/NextStep/software_version | $GREP Blaze > /dev/null
  54. #if ($status == 0) then
  55. if ($ARCH == hppa) then
  56.         set ARCH=hp
  57. endif
  58. endif
  59. endif
  60.  
  61. if ($ARCH != NeXT && $ARCH != i386) then
  62.     $ERROR 'You must run this program on a NeXT or Intel-based computer.'
  63.     exit 1
  64. endif
  65.  
  66. set PROGRAM_NAME=`$BASENAME ${0} .csh`
  67. $ECHO -n "usage: ${PROGRAM_NAME} " > /tmp/_usage_$$
  68. $ECHO '-client hostname -server hostname -domain name [-delete] [-config_domain name]' >> /tmp/_usage_$$
  69. $ECHO 'arguments:' >> /tmp/_usage_$$
  70. $ECHO '    -client hostname   NetInstall client' >> /tmp/_usage_$$
  71. $ECHO '    -server hostname   Server for NetInstall client' >> /tmp/_usage_$$
  72. $ECHO -n '    -domain name       Client' >> /tmp/_usage_$$
  73. $ECHO -n "'" >> /tmp/_usage_$$
  74. $ECHO 's parent NetInfo domain' >> /tmp/_usage_$$
  75. $ECHO '    -delete           Delete client configuration' >> /tmp/_usage_$$
  76. $ECHO '    -config_domain    Domain where servers are recorded (default is "/")' >> /tmp/_usage_$$
  77.  
  78. set DESTROY=$FALSE
  79.  
  80. # Parse command-line options
  81.  
  82. while ($#argv > 0)
  83.     switch (${1})
  84.     case "-help": # Print help message
  85.         $CAT /tmp/_usage_$$
  86.         $RM /tmp/_usage_$$
  87.         exit 1
  88.         breaksw
  89.     case "-client": # Client name
  90.         if ($#argv < 2) then
  91.             $ERROR "${PROGRAM_NAME}: missing argument to -client."
  92.             $CAT /tmp/_usage_$$
  93.             $RM /tmp/_usage_$$
  94.             exit 1
  95.         endif
  96.         set CLIENT_NAME="${2}"
  97.         shift
  98.         breaksw
  99.     case "-server": # Server name
  100.         if ($#argv < 2) then
  101.             $ERROR "${PROGRAM_NAME}: missing argument to -server."
  102.             $CAT /tmp/_usage_$$
  103.             $RM /tmp/_usage_$$
  104.             exit 1
  105.         endif
  106.         set SERVER_NAME="${2}"
  107.         shift
  108.         breaksw
  109.     case "-domain": # Client's parent domain name
  110.         if ($#argv < 2) then
  111.             $ERROR "${PROGRAM_NAME}: missing argument to -domain."
  112.             $CAT /tmp/_usage_$$
  113.             $RM /tmp/_usage_$$
  114.             exit 1
  115.         endif
  116.         set PARENT_DOMAIN="${2}"
  117.         shift
  118.         breaksw
  119.     case "-delete": # Delete client
  120.         set DESTROY=$TRUE    
  121.         breaksw
  122.     case "-config_domain": # Where servers are recorded
  123.         if ($#argv < 2) then
  124.             $ERROR "${PROGRAM_NAME}: missing argument to -config_domain."
  125.             $CAT /tmp/_usage_$$
  126.             $RM /tmp/_usage_$$
  127.             exit 1
  128.         endif
  129.         set CONFIG_DOMAIN="${2}"
  130.         shift
  131.         breaksw
  132.     default: # Unknown flag
  133.         $ERROR "${PROGRAM_NAME}: unknown option ${1}."
  134.         $CAT /tmp/_usage_$$
  135.         $RM /tmp/_usage_$$
  136.         exit 1
  137.         breaksw
  138.     endsw
  139.     shift
  140. end
  141.  
  142. if (${CLIENT_NAME}x == "-UNKNOWN-x") then
  143.         $ERROR "${PROGRAM_NAME}: client name not specified."
  144.         $CAT /tmp/_usage_$$
  145.         $RM /tmp/_usage_$$
  146.         exit 1
  147. endif
  148.  
  149. if (${SERVER_NAME}x == "-UNKNOWN-x") then
  150.         $ERROR "${PROGRAM_NAME}: server name not specified."
  151.         $CAT /tmp/_usage_$$
  152.         $RM /tmp/_usage_$$
  153.         exit 1
  154. endif
  155.  
  156. if (${PARENT_DOMAIN}x == "-UNKNOWN-x") then
  157.         $ERROR "${PROGRAM_NAME}: domain name not specified."
  158.         $CAT /tmp/_usage_$$
  159.         $RM /tmp/_usage_$$
  160.         exit 1
  161. endif
  162.  
  163. $RM /tmp/_usage_$$
  164.  
  165. # Check NetInstall server
  166.  
  167. set SERVER_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP install_root | $AWK '{print $2}'`
  168. set IMAGE_DIR=/Net/${SERVER_NAME}$SERVER_IMAGE
  169.  
  170. $LS $IMAGE_DIR | $GREP "not found"
  171. if ($status == 0) then
  172.     $ERROR 'Can't find NetInstall server $SERVER_NAME directory $IMAGE_DIR.'
  173.     exit 1
  174. endif
  175.  
  176. set NIUTIL=${IMAGE_DIR}$NIUTIL
  177.  
  178. # check client configuration
  179.  
  180. set TEST_CLIENT=`$NIUTIL -read $PARENT_DOMAIN /machines/$CLIENT_NAME | $WC -l`
  181. if (${TEST_CLIENT}x == "0x") then
  182.         $ERROR -n "${PROGRAM_NAME}: can't find: "
  183.         $ERROR -n $PARENT_DOMAIN 
  184.         $ERROR -n ":/machines/$CLIENT_NAME"
  185.         $CAT /tmp/_usage_$$
  186.         $RM /tmp/_usage_$$
  187.         exit 1
  188. endif
  189.  
  190. # Acquire root password for parent NetInfo domain
  191.  
  192. set GET_PW=$TRUE
  193. $ECHO -n "Please enter the root password for the NetInfo domain: "
  194. $ECHO -n '"'
  195. $ECHO -n $PARENT_DOMAIN
  196. $ECHO '"'
  197.  
  198. while ($GET_PW == $TRUE)
  199.     $STTY -echo
  200.     $ECHO -n "Password: "
  201.     set PARENT_PASSWORD=$<
  202.     $STTY echo
  203.     $ECHO ""
  204.     if (${PARENT_PASSWORD}x == "x") then
  205.         set PARENT_PASSWORD='""'
  206.     endif
  207.  
  208.     # Check password 
  209.  
  210.     $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
  211.     set STATUS=`$NIUTIL -read $PARENT_DOMAIN / | $GREP _test_$$`
  212.     if (${STATUS}x == "x") then
  213.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  214.         set USER_INPUT=$<
  215.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  216.             exit 1
  217.         endif
  218.         $SLEEP 2
  219.     else
  220.         $NIUTIL -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN / _test_$$
  221.         set GET_PW=$FALSE
  222.     endif
  223. end
  224.  
  225. # Acquire root password for "config" NetInfo domain
  226.  
  227. set GET_PW=$TRUE
  228. $ECHO -n "Please enter the root password for the NetInfo domain: "
  229. $ECHO -n '"'
  230. $ECHO -n $CONFIG_DOMAIN
  231. $ECHO '"'
  232.  
  233. while ($GET_PW == $TRUE)
  234.     $STTY -echo
  235.     $ECHO -n "Password: "
  236.     set ROOT_PASSWORD=$<
  237.     $STTY echo
  238.     $ECHO ""
  239.     if (${ROOT_PASSWORD}x == "x") then
  240.         set ROOT_PASSWORD='""'
  241.     endif
  242.  
  243.     # Check password 
  244.  
  245.     $NIUTIL -createprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  246.     set STATUS=`$NIUTIL -read $CONFIG_DOMAIN / | $GREP _test_$$`
  247.     if (${STATUS}x == "x") then
  248.         $ECHO -n "Password incorrect.  Do you wish to retry? [yn] "
  249.         set USER_INPUT=$<
  250.         if (${USER_INPUT}x == "nx" || ${USER_INPUT}x == "Nx") then
  251.             exit 1
  252.         endif
  253.         $SLEEP 2
  254.     else
  255.         $NIUTIL -destroyprop -P $ROOT_PASSWORD $CONFIG_DOMAIN / _test_$$
  256.         set GET_PW=$FALSE
  257.     endif
  258. end
  259.  
  260. # Get the server's root image directory name
  261.  
  262. set ROOT_IMAGE=`$NIUTIL -read $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME | $GREP '^install_root: ' | $AWK '{print $2}'`
  263. if (${ROOT_IMAGE}x == "x") then
  264.         $ERROR "${PROGRAM_NAME}: can't find server configuration."
  265.         $CAT /tmp/_usage_$$
  266.         $RM /tmp/_usage_$$
  267.         exit 1
  268. endif
  269.  
  270. if ($DESTROY == $TRUE) then
  271.     # Delete client from server's list of clients
  272.     $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
  273.     $NIUTIL -destroyval -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
  274.  
  275.     # Destroy bootparams
  276.  
  277.     $NIUTIL -destroyprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams 
  278.  
  279.     # All done
  280.  
  281.     $ECHO "NetInstall client configuration deleted."
  282.     exit 0
  283.  
  284. endif
  285.  
  286. # Add new client to server's list of clients
  287. $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME clients $CLIENT_NAME
  288. $NIUTIL -appendprop -P $ROOT_PASSWORD $CONFIG_DOMAIN /locations/install_servers/$SERVER_NAME client_domains $PARENT_DOMAIN
  289.  
  290. # Create bootparams
  291.  
  292. $NIUTIL -createprop -P $PARENT_PASSWORD $PARENT_DOMAIN /machines/$CLIENT_NAME bootparams root=${SERVER_NAME}:$ROOT_IMAGE private=${SERVER_NAME}:$ROOT_IMAGE/private
  293.  
  294. # All done
  295.  
  296. $ECHO "NetInstall client configuration complete."
  297. exit 0
  298.